import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Cookie from 'js-cookie'

Vue.use(ElementUI)

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  store.commit('getToken')
  const token = store.state.user.token
  console.log(token,'token')
  // 如果token不存在,跳转费login页面
  if(!token && to.name !== 'login') {
    next({name:'login'})
  }else if(token && to.name === 'login'){
    next({name: 'home'})
  }else{
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    store.commit('getToken')
    // console.log()
  }
}).$mount('#app')
